<template>
  <div class="app-container">
    <!-- <router-link :to="{ path: '/job/create' }" >
      <el-button type="primary" style="margin-bottom:10px">创建招聘信息</el-button>
    </router-link> -->
    <el-table
      v-loading="listLoading"
      :data="list"
      border
      fit
      highlight-current-row
      style="width: 100%"
      :default-sort="{ prop: 'datetime', order: 'descending' }"
    >
      <!-- <el-table-column align="center" label="ID" width="80">
        <template slot-scope="scope">
          <span>{{ scope.row.id }}</span>
        </template>
      </el-table-column> -->
      <el-table-column
        width="140px"
        align="center"
        label="发布日期"
        prop="datetime"
      >
        <template slot-scope="scope">
          <span>{{ scope.row.datetime }}</span>
        </template>
      </el-table-column>

      <el-table-column min-width="200px" label="招聘信息">
        <template slot-scope="{ row }">
          <el-link :href="row.website" target="_blank">{{ row.title }}</el-link>
        </template>
      </el-table-column>

      <el-table-column min-width="140px" align="center" label="标签">
        <template slot-scope="scope">
          <!-- <span>{{ scope.row.tags }}</span> -->
          <el-tag v-for="(item,index) in scope.row.tags" :key="index+1" style="margin:0px 2px" >{{item}}</el-tag>
          <!-- <el-tag type="success">标签二</el-tag>
          <el-tag type="info">标签三</el-tag>
          <el-tag type="warning">标签四</el-tag>
          <el-tag type="danger">标签五</el-tag> -->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      style="text-align: center"
      v-show="total > 0"
      :total="total"
      :page.sync="listQuery.pageCount"
      :limit.sync="listQuery.size"
      @pagination="getList2"
    />
  </div>
</template>

<script>
import Pagination from '@/components/Pagination' // Secondary package based on el-pagination
import { getJobList, deleteJob, getJobInfoList } from '@/api/job.js'

export default {
  name: 'ArticleList',
  components: { Pagination },
  filters: {
    statusFilter(status) {
      const statusMap = {
        published: 'success',
        draft: 'info',
        deleted: 'danger'
      }
      return statusMap[status]
    }
  },
  data() {
    return {
      list: null,
      total: 0,
      listLoading: true,
      listQuery: {
        pageCount: 1,
        size: 10
      }
    }
  },
  created() {
    this.getList2()
  },
  methods: {
    getList() {
      this.listLoading = true
      getJobList(this.listQuery).then(response => {
        let list = response.data.list
        console.log(list)

        list.forEach(item => {
          item.tags = item.tags.split(",")
        });
        this.list = list
        this.total = response.data.total
        this.listLoading = false
      })
    },
    getList2() {//获取招聘信息列表，根据时空视点获取
      this.listLoading = true
      getJobInfoList(this.listQuery).then(response => {
        let list = response.data.list
        list.forEach(item => {
          item.tags = item.tags.split(",")
        });
        this.list = list
        this.total = response.data.total
        this.listLoading = false
      })
    },
    handleDelete(id) {
      let data = {
        id: id
      }
      deleteJob(data).then(response => {
        this.$message({
          type: 'success',
          message: '删除文章成功'
        })
        this.getList()
      }).catch(err => {
        console.log(err)
      })
    }
  }
}
</script>

<style scoped>
.edit-input {
  padding-right: 100px;
}
.cancel-btn {
  position: absolute;
  right: 15px;
  top: 10px;
}
</style>
